//: TransactionBean.java 05.09.2008 10:04:56Z apt $
package com.devunion.salon.web.bean;

/**
 * @author Timoshenko Alexander
 */
public class TransactionBean implements TransactionInterface {
    private String transNumber;
    private EmployeeBean employee;
    private String customer;
    private ServiceBean service;
    private ProductBean product;
    private GiftcardBean giftcardBean;
    private Integer quantity;
    private Float price;
    private Float taxes;
    private Float total;

    public TransactionBean() {

    }    

    public String getTransNumber() {
        return transNumber;
    }

    public void setTransNumber(String transNumber) {
        this.transNumber = transNumber;
    }

    public EmployeeBean getEmployee() {
        return employee;
    }

    public void setEmployee(EmployeeBean employee) {
        this.employee = employee;
    }

    public String getCustomer() {
        return customer;
    }

    public void setCustomer(String customer) {
        this.customer = customer;
    }

    public Integer getQuantity() {
        if (quantity == null) {
            return 0;
        }
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public Float getPrice() {
        if (product != null) {
            return product.getPrice() * quantity;
        } else if (service != null) {
            return service.getPrice() * quantity;
        } else if (giftcardBean != null) {
            return giftcardBean.getAmount();
        }

        return 0f;
    }

    public void setPrice(Float price) {
        this.price = price;
    }

    public Float getTaxes() {
        if (product != null) {
            return getPrice() * product.getTaxes() / 100;
        }

        if (service != null) {
            return getPrice() * service.getTaxes() / 100;
        }

        if (giftcardBean != null) {
            return getPrice() * giftcardBean.getTaxes() / 100;
        }

        return 0f;
    }

    public void setTaxes(Float taxes) {
        this.taxes = taxes;
    }

    public Float getTotal() {
        return this.getPrice() + this.getTaxes();
    }

    public void setTotal(Float total) {
        this.total = total;
    }

    public ServiceBean getService() {
        return service;
    }

    public void setService(ServiceBean service) {
        this.service = service;
    }

    public ProductBean getProduct() {
        return product;
    }

    public void setProduct(ProductBean product) {
        this.product = product;
    }

    public GiftcardBean getGiftcardBean() {
        return giftcardBean;
    }

    public void setGiftcardBean(GiftcardBean giftcardBean) {
        this.giftcardBean = giftcardBean;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TransactionBean that = (TransactionBean) o;

        if (customer != null ? !customer.equals(that.customer) : that.customer != null) return false;
        if (employee != null ? !employee.equals(that.employee) : that.employee != null) return false;
        if (price != null ? !price.equals(that.price) : that.price != null) return false;
        if (product != null ? !product.equals(that.product) : that.product != null) return false;
        if (service != null ? !service.equals(that.service) : that.service != null) return false;
        if (taxes != null ? !taxes.equals(that.taxes) : that.taxes != null) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = (employee != null ? employee.hashCode() : 0);
        result = 31 * result + (customer != null ? customer.hashCode() : 0);
        result = 31 * result + (service != null ? service.hashCode() : 0);
        result = 31 * result + (product != null ? product.hashCode() : 0);
        result = 31 * result + (price != null ? price.hashCode() : 0);
        result = 31 * result + (taxes != null ? taxes.hashCode() : 0);
        return result;
    }
}
